﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Joyintech.Model.inpiao365;
using Joyintech.BLL.inpiao365;
using System.Data;

namespace Joyintech.Web.inpiao365.PhenixTicket
{
    public partial class ajax_filmclist : System.Web.UI.Page
    {
        /// <summary>
        /// 今天日期
        /// </summary>
        protected string today;
        /// <summary>
        /// 明天日前
        /// </summary>
        protected string tomorrow;
        /// <summary>
        /// 后天日期
        /// </summary>
        protected string nexday;
        /// <summary>
        /// 今天星期几
        /// </summary>
        protected string todayweek;
        /// <summary>
        /// 明天星期几
        /// </summary>
        protected string tomorrowweek;
        /// <summary>
        /// 后天星期几
        /// </summary>
        protected string nexdayweek;
        /// <summary>
        /// 电影ID
        /// </summary>
        protected string movieid;
        /// <summary>
        /// 地区ID
        /// </summary>
        protected string areaid;
        /// <summary>
        /// 城市ID
        /// </summary>
        protected string cityid;
        /// <summary>
        /// 影院ID
        /// </summary>
        protected string cinemaid;
        /// <summary>
        /// 选定日期
        /// </summary>
        protected string checkdate;
        /// <summary>
        /// 城市集合
        /// </summary>
        protected List<systemArea> citylist;
        /// <summary>
        /// 地区集合
        /// </summary>
        protected List<systemArea> citylist_area;
        /// <summary>
        /// 影院集合
        /// </summary>
        protected List<Joyintech.Model.inpiao365.theater> theaterlist;
        /// <summary>
        /// 场次集合
        /// </summary>
        protected List<screeningsExtend> scrieentinglist;
        /// <summary>
        /// 影院信息扩展类
        /// </summary>
        protected ThreaterExtend threaterExtend;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                today = DateTime.Now.ToString("yyyy-MM-dd");
                tomorrow = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");
                nexday = DateTime.Now.AddDays(2).ToString("yyyy-MM-dd");
                todayweek = TransformDay((int)DateTime.Now.DayOfWeek);
                tomorrowweek = TransformDay((int)DateTime.Now.AddDays(1).DayOfWeek);
                nexdayweek = TransformDay((int)DateTime.Now.AddDays(2).DayOfWeek);
                InitView();
                BindCinema();
            }
        }

        /// <summary>
        /// 初始化页面变量
        /// </summary>
        private void InitView()
        {
            cityid = Request["cityid"];
            areaid = Request["areaid"];
            movieid = Request["filmid"];
            checkdate = Request["date"] == "" ? DateTime.Now.ToString("yyyy-MM-dd") : Request["date"];
            cinemaid = Request["cinemaindex"];
            systemArea_BLL areabll = new systemArea_BLL();
            citylist = areabll.GetModelList(" Preencode='340000' ");
            citylist_area = areabll.GetModelList(" Preencode='" + cityid + "' ");
            theater_BLL theaterbll = new theater_BLL();
            if (areaid == "0")
            {
                theaterlist = theaterbll.GetModelList(" cityid='" + cityid + "'");
            }
            else
            {
                theaterlist = theaterbll.GetModelList(" AreaId='" + areaid + "'");
            }
            if (cinemaid == "0")
            {
                if (theaterlist != null && theaterlist.Count > 0)
                {
                    cinemaid = theaterlist.First().TheaterId.ToString();
                }
            }

        }

        /// <summary>
        /// 绑定电影场次播放信息
        /// </summary>
        private void BindCinema()
        {
            screenings_BLL screeningbll = new screenings_BLL();
            scrieentinglist = screeningbll.GetList(movieid, cinemaid, DateTime.Parse(checkdate));
            threaterExtend = screeningbll.GetThreaterExtendModel(int.Parse(cinemaid));
        }

        /// <summary>
        /// 转换成中文星期
        /// </summary>
        /// <param name="week"></param>
        /// <returns></returns>
        private string TransformDay(int week)
        {
            string xingqi = string.Empty;
            if (week == 0)
            {
                xingqi = "星期日";
            }
            else if (week == 1)
            {
                xingqi = "星期一";
            }
            else if (week == 2)
            {
                xingqi = "星期二";
            }
            else if (week == 3)
            {
                xingqi = "星期三";
            }
            else if (week == 4)
            {
                xingqi = "星期四";
            }
            else if (week == 5)
            {
                xingqi = "星期五";
            }
            else
            {
                xingqi = "星期六";
            }

            return xingqi;
        }
    }



}